package com.itcodai.config.swagger;

import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;

/**
 * @author c-fanqj
 * @date 2023/3/23
 * @apiNote 把/swagger-ui.html这个路径映射到对应的目录META-INF/resources/下面
 */
//@Configuration
//@EnableWebMvc
//@EnableSwagger2
// extends WebMvcConfigurerAdapter
// implements WebMvcConfigurer
public class WebMvcConfig /* extends WebMvcConfigurerAdapter*/ {

    //@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        //registry.addResourceHandler("/templates/**")
        //        .addResourceLocations("classpath:/META-INF/resources/templates/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

        //super.addResourceHandlers(registry);
    }

    /** 访问静态资源
     * SpringBoot自动配置本身并不会把/swagger-ui.html
     * 这个路径映射到对应的目录META-INF/resources/下面
     * 采用WebMvcConfigurerAdapter将swagger的静态文件进行发布;
     */
    //@Override
    /*public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/public/");

        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/");

        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

        //将所有/static/** 访问都映射到classpath:/static/ 目录下
        //registry.addResourceHandler("/static/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/static/");
        //super.addResourceHandlers(registry);
        //WebMvcConfigurer.super.addResourceHandlers(registry);
    }*/

    /*@Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        //WebMvcConfigurer.super.configureDefaultServletHandling(configurer);
        configurer.enable();
    }*/
}